package fun.chutianshu.springsecurity_04.service.impl;

import fun.chutianshu.springsecurity_04.dao.SysPermissionRoleDao;
import fun.chutianshu.springsecurity_04.entity.SysPermissionRole;
import fun.chutianshu.springsecurity_04.service.SysPermissionRoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 权限角色表(SysPermissionRole)表服务实现类
 *
 * @author makejava
 * @since 2021-05-25 07:30:26
 */
@Service("sysPermissionRoleService")
public class SysPermissionRoleServiceImpl implements SysPermissionRoleService {
    @Resource
    private SysPermissionRoleDao sysPermissionRoleDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public SysPermissionRole queryById(Long id) {
        return this.sysPermissionRoleDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<SysPermissionRole> queryAllByLimit(int offset, int limit) {
        return this.sysPermissionRoleDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param sysPermissionRole 实例对象
     * @return 实例对象
     */
    @Override
    public SysPermissionRole insert(SysPermissionRole sysPermissionRole) {
        this.sysPermissionRoleDao.insert(sysPermissionRole);
        return sysPermissionRole;
    }

    /**
     * 修改数据
     *
     * @param sysPermissionRole 实例对象
     * @return 实例对象
     */
    @Override
    public SysPermissionRole update(SysPermissionRole sysPermissionRole) {
        this.sysPermissionRoleDao.update(sysPermissionRole);
        return this.queryById(sysPermissionRole.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.sysPermissionRoleDao.deleteById(id) > 0;
    }
}